#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "WingMayeService.h"
#include <DApplication>
#include <DGuiApplicationHelper>
#include <DListWidget>
#include <DMainWindow>
#include <QAction>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QHBoxLayout>
#include <QListWidgetItem>
#include <QMap>
#include <QMenu>
#include <QPoint>
#include <QProcess>
#include <QStringList>
#include <QSystemTrayIcon>
#include <QWidget>

DWIDGET_USE_NAMESPACE

class MainWindow : public DMainWindow {
  Q_OBJECT
public:
  MainWindow(DMainWindow *parent = nullptr);
  ~MainWindow();

private slots:
  void on_listcat_itemClicked(QListWidgetItem *item);

  void on_listItems_itemClicked(QListWidgetItem *item);
  void on_listItems_itemPressed(QListWidgetItem *item);

  void on_listcat_itemSelectionChanged();

  void on_newcat_triggered(bool checked); // new a catagory
  void on_delcat_triggered(bool checked); // delete a catagory
  void on_clrcat_triggered(bool checked); // wipe out all the catagories
  void on_rncat_triggered(bool checked);  // rename a catagory

  void on_newitem_triggered(bool checked);  // new a shorcut item
  void on_edititem_triggered(bool checked); // edit a shorcut item
  void on_delitem_triggered(bool checked);  // delete a shorcut item
  void on_clritem_triggered(bool checked);  // wipe out aall shorcut items

  void on_setting_triggered(bool checked);

  void on_show_catMenu(const QPoint &p);
  void on_show_itemsMenu(const QPoint &p);

  void on_menuexit_triggered(bool checked);

private:
  void setTheme(DGuiApplicationHelper::ColorType);
  void parse(QUrl item, ShortCutInfo &r); // note : no catagory specific
  void addshortcut(ShortCutInfo si);

protected:
  void dropEvent(QDropEvent *event);
  void dragEnterEvent(QDragEnterEvent *event);

private:
  DECLARE_CONTENT("MWND")

  QStringList catagories;                         // all catgories
  QList<ShortCutInfo> orignshortcuts;             // orign shortcuts
  QMap<QString, QList<ShortCutInfo> *> shortcuts; // catgorized shorcuts
  QString curCat;                                 // the current catagory

  QWidget *w;
  QHBoxLayout *layui;
  DListWidget *listitems;
  DListWidget *listcat;
  QProcess pstart;

  QMenu *menucat;
  QMenu *menuitem;
  QMenu *menusys;
  QMenu *menutitle;

  QSystemTrayIcon *systray;
};

#endif // MAINWINDOW_H
